using System;
using System.Security;

namespace Oracle.ManagedDataAccess.Client
{
	public sealed class OracleCredential
	{
		internal SecureString m_securePassword;

		internal string m_userId = string.Empty;

		internal SecureString m_secureProxyPassword;

		internal string m_proxyUserId = string.Empty;

		internal OracleDBAPrivilege m_dbaPrivilege;

		internal bool m_bInternalUse;

		public bool m_bUserIdSet;

		public bool m_bPasswordSet;

		public bool m_bProxyUserIdSet;

		public bool m_bProxyPasswordSet;

		public string UserId => m_userId;

		public SecureString Password => m_securePassword;

		public string ProxyUserId => m_proxyUserId;

		public SecureString ProxyPassword => m_secureProxyPassword;

		public OracleDBAPrivilege DBAPrivilege => m_dbaPrivilege;

		public OracleCredential(string userId, SecureString password)
		{
			if (userId == null)
			{
				throw new ArgumentNullException("userId");
			}
			if (userId.Length == 0)
			{
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_INVALID_VALUE, "userId"));
			}
			if (userId.Trim() == "/" || userId.Replace(" ", string.Empty) == "\"/\"")
			{
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_INVALID_VALUE, "userId"));
			}
			if (password == null)
			{
				throw new ArgumentNullException("password");
			}
			if (password.Length == 0)
			{
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_INVALID_VALUE, "password"));
			}
			if (!password.IsReadOnly())
			{
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.PWD_READONLY, "password"));
			}
			m_userId = userId;
			m_bUserIdSet = true;
			m_securePassword = password;
			m_bPasswordSet = true;
		}

		public OracleCredential(string userId, SecureString password, OracleDBAPrivilege dbaPrivilege)
			: this(userId, password)
		{
			if (dbaPrivilege != 0 && dbaPrivilege != OracleDBAPrivilege.SYSDBA && dbaPrivilege != OracleDBAPrivilege.SYSOPER && dbaPrivilege != OracleDBAPrivilege.SYSASM && dbaPrivilege != OracleDBAPrivilege.SYSBACKUP && dbaPrivilege != OracleDBAPrivilege.SYSRAC && dbaPrivilege != OracleDBAPrivilege.SYSKM && dbaPrivilege != OracleDBAPrivilege.SYSDG)
			{
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_INVALID_VALUE, "dbaPrivilege"));
			}
			m_dbaPrivilege = dbaPrivilege;
		}

		public OracleCredential(string userId, SecureString password, string proxyUserId, SecureString proxyPassword)
		{
			if (userId == null)
			{
				throw new ArgumentNullException("userId");
			}
			if (userId.Length == 0)
			{
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_INVALID_VALUE, "userId"));
			}
			if (proxyUserId == null)
			{
				throw new ArgumentNullException("proxyUserId");
			}
			if (proxyUserId.Length == 0)
			{
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_INVALID_VALUE, "proxyUserId"));
			}
			if (userId.Trim() == "/" || userId.Replace(" ", string.Empty) == "\"/\"")
			{
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_INVALID_VALUE, "userId"));
			}
			if (proxyUserId.Trim() == "/" || proxyUserId.Replace(" ", string.Empty) == "\"/\"")
			{
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_INVALID_VALUE, "proxyUserId"));
			}
			if (password != null && !password.IsReadOnly())
			{
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.PWD_READONLY, "password"));
			}
			if (proxyPassword == null)
			{
				throw new ArgumentNullException("proxyPassword");
			}
			if (proxyPassword.Length == 0)
			{
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_INVALID_VALUE, "proxyPassword"));
			}
			if (!proxyPassword.IsReadOnly())
			{
				throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.PWD_READONLY, "proxyPassword"));
			}
			m_userId = userId;
			m_bUserIdSet = true;
			m_securePassword = password;
			if (password != null && password.Length != 0)
			{
				m_bPasswordSet = true;
			}
			m_proxyUserId = proxyUserId;
			m_bProxyUserIdSet = true;
			m_secureProxyPassword = proxyPassword;
			m_bProxyPasswordSet = true;
		}

		internal OracleCredential(SecureString password, SecureString proxyPassword)
		{
			m_bInternalUse = true;
			m_securePassword = password;
			m_secureProxyPassword = proxyPassword;
		}
	}
}
